# -*- coding: utf-8 -*-
# @Time    : 2021/8/31 0:21
# @Author  : BrandonGT
# @FileName: 05_PyQt5_QAbstractButton_自定义绘制案例.py

# 1. 导入包和模块
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys

# 2. 创建一个应用程序对象
app = QApplication(sys.argv)

# 3. 创建控件
window = QWidget()

# 3.1 设置控件
window.setWindowTitle("")
window.resize(500, 500)

class CustomBtn(QAbstractButton):
    def paintEvent(self, QPaintEvent):

        painter = QPainter(self)
        pen = QPen(QColor(0, 0, 0), 2)
        painter.setPen(pen)
        painter.drawText(50, 50, self.text())

btn = CustomBtn(window)
btn.resize(100, 100)
btn.move(100, 100)
btn.setText("1")
def addone():
    count = int(btn.text())
    count += 1
    btn.setText(str(count))

btn.clicked.connect(addone)

# 3.2 展示控件
window.show()

# 4. 应用程序执行，进入消息循环
sys.exit(app.exec_())